<template>
  <!--订单  -->
  <div>
    <div id="page">
      <!--顶部-->
      <!-- top1 -->
      <div id="order_top">
        <div class="top">
          <span class="iconfont arrow_l">&#xe603;</span>
          <h2 class="qrdd">确认订单</h2>
          <p>
            <span class="iconfont">&#xe64a;</span>
            <span class="iconfont">&#xe614;</span>
            <i class="line"></i>
          </p>
        </div>
        <div class="bottom"></div>
      </div>

      <!-- address -->
      <div id="address" v-if="this.$route.query.id">
        <p>{{ lists.username }} {{ lists.userphone }}</p>
        <p>{{ lists.location }} {{ lists.useraddress }}</p>
      </div>
      <div id="address" v-else>
        <span
          @click="adds()"
          style="
            width: 1.5rem;
            height: 0.5rem;
            display: inline-block;
            border: 1px solid #ff6700;
            line-height: 0.5rem;
            text-align: center;
            color: #ff6700;
            margin: 0.5rem 0 0 2rem;
            position: relative;
          "
          >点击添加地址</span
        >
      </div>
      <div id="order_main">
        <div class="top">
          <p><span></span> 品牌精选</p>
          <p>
            <span>已免运费</span>
            <span></span>
            <span>领券</span>
          </p>
        </div>
        <ul>
          <li v-for="item in shoplist" :key="item.id">
            <img :src="$pre + item.img" alt="" />
            <div class="box">
              <p>{{ item.goodsname }}<br />面奶150ml 浸透舒缓</p>
              <p>
                ￥ <span>{{ item.price }}</span>
              </p>
              <p><span>7天无理由退货</span><span>特价</span></p>
              <p>x{{ item.num }}</p>
            </div>
          </li>
        </ul>
        <div class="bottom">
          <p>
            发票类型<span class="span1">不开发票 <em></em></span>
          </p>
          <p>售后免邮<span class="span">部分商家赠送</span></p>
          <p>
            买家留言<span class="span">填写内容需要与协商并确认,35字以内</span>
          </p>
        </div>
      </div>

      <div id="Order">
        <p>
          商品金额<span class="span1">￥{{ order.countmoney }}</span>
        </p>
        <p>优惠活动<span class="span2">-￥200</span></p>
        <p>
          优惠券<span class="span3">暂无可用 <em></em></span>
        </p>
      </div>

      <div id="total">
        <p><span>合计</span>已免运费</p>
        <p>
          <span>￥{{ order.countmoney }}</span
          >已优惠￥200元
        </p>
        <p @click="addorder()">确认订单</p>
      </div>
    </div>
  </div>
</template>

<script>
import { addressList, orderAdd } from "../../utils/api";
import { mapGetters, mapActions } from "vuex";
import { Toast } from "vant";
export default {
  props: [],
  components: {},
  data() {
    return {
      users: {},
      lists: {},
      order: {},
      shoplist: [],
    };
  },
  computed: {
    ...mapGetters({}),
  },
  methods: {
    ...mapActions({}),
    adds() {
      this.$router.push("/addressAdd");
    },
    addorder() {
      if (this.$route.query.id) {
        orderAdd(this.order).then((res) => {
          if (res.data.code == 200) {
            this.$router.push("/pay");
          }
        });
      } else {
        Toast("请填写地址");
      }
    },
  },
  mounted() {
    //用户信息
    this.users = sessionStorage.getItem("user")
      ? JSON.parse(sessionStorage.getItem("user"))
      : {};
    //选中商品信息
    this.shoplist = sessionStorage.getItem("shoplist")
      ? JSON.parse(sessionStorage.getItem("shoplist"))
      : {};
    //地址添加信息
    this.order = sessionStorage.getItem("shoper")
      ? JSON.parse(sessionStorage.getItem("shoper"))
      : {};
    this.order = {
      ...this.order,
      uid: this.users.uid,
      countmoney: Number(this.order.countmoney),
      addressid: this.$route.query.id ? Number(this.$route.query.id) : "",
    };
    // console.log(this.order);
    if (this.$route.query.id) {
      addressList({ uid: this.users.uid, id: this.$route.query.id }).then(
        (res) => {
          let obj = res.data.list[0] ? res.data.list[0] : {};
          this.lists = obj;
          //console.log(this.lists);
        }
      );
    }
  },
};
</script>

<style scoped>
#top1 .top .qrdd {
  margin: 0 1.2rem 0 2rem;
}
html,
body,
#page {
  height: 100%;
}
#page {
  display: flex;
  flex-direction: column;
  margin: 0 auto;
  max-width: 7.5rem;
}
/*top1*/
#order_top {
  height: 2.85rem;
  display: flex;
  flex-direction: column;
}
#order_top .top {
  height: 0.64rem;
  background: #ff6040;
  padding: 0.28rem 0.12rem 0.28rem 0.32rem;
  color: #ffdfd8;
  display: flex;
  align-items: center;
}
#order_top .top h2 {
  margin: 0 1.2rem 0 2.5rem;
  font-size: 0.32rem;
}
#order_top .top .arrow_l {
  font-size: 0.34rem;
}
#order_top .top p {
  width: 1.74rem;
  height: 0.64rem;
  border: 1px solid #ff8367;
  border-radius: 0.54rem;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  position: relative;
}
#order_top .top p span {
  width: 50%;
  height: 100%;
  line-height: 0.64rem;
  text-align: center;
}
#order_top .top p span.iconfont {
  font-size: 0.3rem;
  color: #ffdfd8;
}
#order_top .top p .line {
  width: 1px;
  height: 0.37rem;
  position: absolute;
  top: 0.12rem;
  left: 0.86rem;
  background-color: #ff896e;
}
#order_top .bottom {
  height: 1.65rem;
  display: flex;
  background: linear-gradient(#ff6040, #ff8476);
}
/*address*/
#address {
  height: 2.1rem;
  width: 7.1rem;
  background-color: #fff;
  margin-left: 0.2rem;
  border-radius: 0.2rem;
  padding: 0.42rem;
  box-sizing: border-box;
  position: relative;
  left: 0;
  top: -1.5rem;
}
#address p:nth-child(1) {
  font-size: 0.3rem;
  color: #333;
  font-weight: bold;
}
#address p:nth-child(2) {
  line-height: 0.38rem;
  font-size: 0.26rem;
  color: #666;
  margin-top: 0.2rem;
}
#order_main {
  display: flex;
  flex-direction: column;
  flex: 1;
  margin-top: -1.3rem;
}
#order_main .top {
  height: 0.7rem;
  background-color: #fff;
  padding: 0.2rem;
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#order_main .top p:nth-child(1) {
  font-size: 0.3rem;
  color: #333;
  font-weight: bold;
}
#order_main .top p:nth-child(1) span {
  width: 0.37rem;
  height: 0.32rem;
  background: url(../../assets/img/confirm.png);
  background-size: 0.37rem 0.32rem;
  display: inline-block;
  vertical-align: middle;
  margin-bottom: 0.03rem;
}
#order_main .top p:nth-child(2) {
  font-size: 0.2rem;
  color: #333;
}
#order_main .top p:nth-child(2) span:nth-child(1) {
  width: 1.2rem;
  text-align: right;
  display: inline-block;
  margin-right: 0.1rem;
}
#order_main .top p:nth-child(2) span:nth-child(2) {
  height: 0.25rem;
  width: 0.02rem;
  background-color: #979797;
  display: inline-block;
  vertical-align: middle;
  margin-bottom: 0.03rem;
}
#order_main .top p:nth-child(2) span:nth-child(3) {
  font-size: 0.22rem;
  color: #ff6242;
  margin-left: 0.1rem;
}
#order_main ul {
  height: 2.5rem;
  background-color: #fff;
  display: flex;
  flex-direction: column;
}
#order_main ul li {
  display: flex;
  justify-content: space-between;
  flex: 1;
  height: 2.6rem;
  padding: 0.2rem;
  box-sizing: border-box;
}
#order_main ul li img {
  width: 2.16rem;
  height: 2.22rem;
}
#order_main ul li .box {
  position: relative;
}
#order_main ul li .box p:nth-child(1) {
  font-size: 0.3rem;
  color: #333;
  line-height: 0.46rem;
}
#order_main ul li .box p:nth-child(2) {
  font-size: 0.14rem;
  color: #ff6040;
  margin-top: 0.23rem;
}
#order_main ul li .box p:nth-child(2) span {
  font-size: 0.38rem;
  font-weight: bold;
}
#order_main ul li .box p:nth-child(3) {
  font-size: 0.18rem;
  color: #fff;
  margin-top: 0.24rem;
}
#order_main ul li .box p:nth-child(3) span {
  text-align: center;
  line-height: 0.35rem;
  display: inline-block;
}
#order_main ul li .box p:nth-child(3) span:nth-child(1) {
  width: 1.95rem;
  height: 0.35rem;
  background-color: #ff8066;
}
#order_main ul li .box p:nth-child(3) span:nth-child(2) {
  width: 0.75rem;
  height: 0.35rem;
  background-color: #ff8066;
  margin-left: 0.1rem;
}
#order_main ul li .box p:nth-child(4) {
  height: 0.28rem;
  width: 0.4rem;
  color: #333;
  font-size: 0.22rem;
  line-height: 0.28rem;
  text-align: center;
  position: absolute;
  right: 0;
  bottom: 0.65rem;
}
#order_main .bottom {
  height: 2.3rem;
  background-color: #fff;
  padding: 0 0.2rem;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: space-around;
}
#order_main .bottom p {
  display: flex;
  justify-content: space-between;
  font-size: 0.24rem;
  color: #333;
  font-weight: bold;
}
#order_main .bottom p em {
  width: 0.2rem;
  height: 0.16rem;
  background: url(../../assets/img/right.png);
  background-size: 0.2rem 0.16rem;
  display: inline-block;
}
#order_main .bottom p .span1 {
  color: #333;
  font-weight: normal;
}
#order_main .bottom p .span {
  font-weight: normal;
  color: #747474;
}
#Order {
  height: 1rem;
  background-color: #fff;
  padding: 0 0.3rem 4rem 0.3rem;
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  margin: 0.15rem 0 0.5rem 0;
}
#Order p {
  display: flex;
  justify-content: space-between;
  font-size: 0.24rem;
  color: #333;
  font-weight: bold;
  margin-top: 0.4rem;
}
#Order p span {
  font-weight: normal;
}
#Order p .span1 {
  font-size: 0.2rem;
  color: #666;
}
#Order p .span2 {
  font-size: 0.2rem;
  color: #ff6040;
}
#Order p .span3 em {
  width: 0.2rem;
  height: 0.16rem;
  background: url(../../assets/img/right.png);
  background-size: 0.2rem 0.16rem;
  display: inline-block;
}
#total {
  width: 100vw;
  height: 1.7rem;
  border-top: 1px solid #ccc;
  background-color: #fff;
  padding-left: 0.2rem;
  box-sizing: border-box;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: fixed;
  left: 0;
  bottom: 0;
  margin: 0.2rem 0 0 0;
}
#total p:nth-child(1) {
  font-size: 0.2rem;
  color: #9e9e9e;
}
#total p:nth-child(1) span {
  display: block;
  color: #333;
  font-size: 0.3rem;
  font-weight: bold;
}
#total p:nth-child(2) {
  font-size: 0.2rem;
  color: #9e9e9e;
}
#total p:nth-child(2) span {
  display: block;
  color: #ff6040;
  font-size: 0.32rem;
  font-weight: bold;
  text-align: right;
}
#total p:nth-child(3) {
  width: 2.2rem;
  height: 0.99rem;
  line-height: 0.99rem;
  background-color: #ff6040;
  color: #fff;
  font-size: 0.32rem;
  text-align: center;
  font-weight: bold;
  margin-left: 1.6rem;
}
</style>